package com.mtung.dubbo.discover;

import org.I0Itec.zkclient.ZkClient;

import java.util.List;

/**
 * 服务发现
 * @author : zhenguo.yao
 * @date : 2020/3/23 0023 10:27
 */
public class ServiceDiscoverImpl implements ServiceDiscover {

    /**
     * zk连接地址
     */
    private final String zkServers = "127.0.0.1";
    /**
     * 会话时间
     */
    private final int connectionTimeout = 5000;
    /***
     * zkClient
     */
    private ZkClient zkClient;

    private String rootNamePath = "/mtung_rpc";

    public ServiceDiscoverImpl() {
        // 1. 连接zk连接
        zkClient = new ZkClient(zkServers, connectionTimeout);
    }

    /**
     * 服务发现
     * @param serviceName
     * @return
     */
    public List<String> getDiscover(String serviceName) {
        List<String> children = zkClient.getChildren(rootNamePath + "/" + serviceName + "/providers");
        return children;
    }
}
